<?php
/*session_start();
$id = $_SESSION['user_id'];
echo "id $id <br />";
if($id):
	$id = $_SESSION['user_id'];
	echo "delete session<br />";
	$result = api("$id/sessions/","DELETE","");
	unset($_SESSION['user_id']);
else:
	echo "starting session<br />";
	$result = api("sessions/","POST","email=kac173@pitt.edu&password=pizza");
	$result = json_decode($result,true);
	$_SESSION['user_id'] = $result['user_id'];
endif;
print_r($result);*/

function api($page, $method, $data){
	$url = "http://localhost/spork/api/";
	$url .= $page;
	
	$curl = "c:/xampp/htdocs/spork/curl/curl";
	
	$cmd = "$curl ";
	
	if(strcmp($page,"sessions/")==0)
		$cmd .= "-c ";
	else
		$cmd .= "-b ";
	$cmd .= "cookie.txt";
	
	switch($method){
	case "POST":
		$cmd .= " --data \"$data\"";
		break;
	case "PUT":
		$cmd .= " -X PUT -d \"$data\"";
		break;
	case "DELETE":
		$cmd .= " -X DELETE -d \"$data\"";
		break;
	case "GET":
		if($data)
			$url .= "?$data";
		break;
	}
	
	$cmd .= " $url";
	
	//echo $cmd."<br />";
	return shell_exec($cmd);
}
?>